package com.lixiaoyu.controller;

import com.lixiaoyu.entity.Express;
import com.lixiaoyu.service.ExpressService;
import com.lixiaoyu.service.impl.ExpressServiceImpl;

/**
 * 控制层 调用方法
 */
public class ExpressController {

    ExpressService expressService= new ExpressServiceImpl();


    /**
     * 登陆操作
     * @param userName 账号
     * @param passWord 密码
     * @return int 0管理员登陆成功-1普通用户登陆成功-2密码错误-3账户不存在
     */
    public int goLogin(String userName, int passWord) {
        String[][] userPassList = new String[1][2];
        try{
            //获取账户和密码
            userPassList = expressService.getUserPassWord(userName,passWord);
        }catch(NullPointerException e){
            userPassList[0][0] = "";
            userPassList[0][1] = "";
        }
        if(userName.equals(userPassList[0][0])){
            if(Integer.toString(passWord).equals(userPassList[0][1])){
                if(userName.equals("admin")){
                    return 0;
                }else{
                    return 1;
                }
            }
            return 2;
        }
        return 3;

    }


    /**
     * 查询快递  条件：取件码
     * @param getExpressCode 取件码
     * @return
     */
    public String[][] selectUserExpress(int getExpressCode) {
        String[][] expressList = expressService.selectUserExpress(getExpressCode);
        return expressList;
    }

    /**
     * 取出快递
     * @param getExpressCode 取件码
     */
    public void deleteUserExpress(int getExpressCode) {
         expressService.deleteUserExpress(getExpressCode);
    }

    /**
     * 添加快递
     * @param express : 实体 存放单号和快递公司
     */
    public void addAdminExpress(Express express) {
         expressService.addAdminExpress(express);
    }

    /**
     * 快递修改
     * @param next 取件码
     * @param next1 快递单号
     * @param next2 快递公司
     * @return
     */
    public int updateAdminExpress(int next, String next1, String next2) {
        return expressService.updateAdminExpress(next,next1,next2);
    }

    /**
     * 查询所有的快递柜
     * @return 1 成功   0 失败
     */
    public int selectAdminExpress() {
        return expressService.selectAdminExpress();
    }
}
